package com.atguigu.gmall.service.impl;

import com.atguigu.gmall.entity.UserInfo;
import com.atguigu.gmall.mapper.UserMapper;
import com.atguigu.gmall.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,UserInfo> implements UserService {
    @Override
    public UserInfo queryUserByUserLoginParams(UserInfo userInfoParams){
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("login_name",userInfoParams.getLoginName());
        UserInfo userInfo = baseMapper.selectOne(queryWrapper);
        if (ObjectUtils.isEmpty(userInfo)){
            // TODO: 2021/9/21 注册用户
        }//不存在该用户，注册
//        String passwd = userInfoParams.getPasswd();//前端去验证不为空
        String passwordByMD5 = DigestUtils.md5DigestAsHex(userInfoParams.getPasswd().getBytes());
        if (userInfo.getPasswd().equals(passwordByMD5))
            return userInfo;//密码验证正确
        return null;
    }
}
